package com.wangxiang.sys.manage.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.wangxiang.sys.manage.entity.AuthEntity;
import com.wangxiang.sys.manage.entity.RoleEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wangxiang.sys.manage.entity.MenuEntity;
import com.wangxiang.sys.manage.service.MenuService;
import com.wangxiang.common.utils.PageUtils;
import com.wangxiang.common.utils.R;



/**
 * 
 *
 * @author wangxiang
 * @email 2293672863@qq.com
 * @date 2022-03-05 16:29:54
 */
@RestController
@RequestMapping("sys/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;
    /**
     * 菜单的添加
     */
    @RequestMapping("add")
    public R add(@RequestBody MenuEntity menu){
        //判断空，不能为空的，id,title,level,parentId
        if (menu.equals(null)){
            return R.error("数据为空，提交失败");
        }

        return null;
    }
    /**
     * 菜单
     */
    @RequestMapping("/getMenu")
    public R menu(@RequestBody RoleEntity roleEntity){
        System.out.println("角色id"+roleEntity);
        List<MenuEntity> menu = menuService.getMenu(roleEntity.getId());
        return R.ok().put("menu",menu).put("msg","菜单");
    }





    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") int id){
		MenuEntity menu = menuService.getById(id);
        return R.ok().put("menu", menu);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody MenuEntity menu){
		menuService.save(menu);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MenuEntity menu){
		menuService.updateById(menu);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody int[] ids){
		menuService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
